﻿<html>
    <meta charset="utf-8"/>
    <body>
        <form action="www.baidu.com" onsubmit="return test()">
            <input type="text" id="uname"/>
            <input type="submit" value="提交"/>
        </form>
    </body>
    <script>
        function test(){
            var input_obj = document.getElementById("uname");
            if(input_obj.value){
                return true;
            }else{
                alert("输入用户名")
                return false;
            }
        }
    </script>
 </html>